package ca.seia.comp6521.a1.util;

public class MemoryCalculator {


	public static final int MB = 1048576;
	public static final int KB = 1024;
	public static final int PRIMITIVE_INTEGER_BYTE_SIZE = 4;
	public static final int VM32_INTEGER_BYTE_SIZE = 16;
	public static final int VM64_INTEGER_BYTE_SIZE = 32;
	public static final int INTEGER_BYTE_SIZE = 4;
	
	
	
	/**
	 * 
	 * @param fileSize
	 * @param megabytes
	 * @return
	 */
	/*
	public static int getNumberOfSubLists(long fileSize, int megabytes) {
		return (int) Math.ceil((fileSize / (double) (megabytes * MB)));
	}
	*/

	
	/**
	 * 
	 * @param megabytes
	 * @return the number of Primitive Ints that can fit in megabytes
	 */
	public static int getNumberOfPrimitiveInt(int megabytes) {
		return getNumberOfIntegers(megabytes, PRIMITIVE_INTEGER_BYTE_SIZE);
	}
	
	/**
	 * 
	 * @param megabytes 
	 * @return the number of Integers that can fit in megabytes 
	 */
	public static int getNumberOfIntegers(int megabytes) {
		return getNumberOfIntegers(megabytes, getIntegerVMByteSize());
	}
	
	public static int getNumberOfIntegers(int megabytes, int integerByteSize) {
		return (int) Math.ceil((megabytes * MB) / (double)integerByteSize);
	}
		
	public static int getIntegerVMByteSize() {
		if (getVMBitSize() == 64) 
			return VM64_INTEGER_BYTE_SIZE;
		return VM32_INTEGER_BYTE_SIZE;
	}
	
	public static int getVMBitSize() {
		return Integer.parseInt(System.getProperty("sun.arch.data.model"));
	}
}
